package cn.kdyzm.twofa.service.impl;

import cn.kdyzm.twofa.entity.SysUser;
import cn.kdyzm.twofa.mapper.ISysUserMapper;
import cn.kdyzm.twofa.service.ILoginService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author kdyzm
 * @date 2025/6/16
 */
@Slf4j
@Service
@AllArgsConstructor
public class LoginServiceImpl implements ILoginService {

    private final ISysUserMapper sysUserMapper;

    @Override
    public SysUser login(String userName, String password) {
        SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, userName));
        if (Objects.isNull(sysUser)) {
            return null;
        }
        String password1 = sysUser.getPassword();
        if (password1.equals(password)) {
            return sysUser;
        }
        return null;
    }
}
